package hutool.date;

import cn.hutool.core.date.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/5/22 22:49
 * @since JDK 1.8
 */
public class DateUtils {

    public static void main(String[] args) {
        new DateUtils().Demo3();
    }


    public void Demo3(){
        Date date = DateUtil.date();
        //获得年的部分
        int year=DateUtil.year(date);

        //获得月份，从0开始计数
        int month=DateUtil.month(date);

        System.out.println(year+" "+month);
    }

    //获取当前时间
    public void Demo2(){
        String now = DateUtil.now();
        System.out.println(now);
    }


    //将日期字符串转为时间
    public void Demo1() throws Exception{
        String dateStr = "2017-03-01";
        Date date = DateUtil.parse(dateStr, "yyyy-MM-dd");
        System.out.println(date.getTime());
        //############################################
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss");
        String nowDate=simpleDateFormat.format(new Date());
        Date date1=simpleDateFormat.parse(nowDate);
    }
}
